import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import javax.swing.text.html.HTMLEditorKit;

public class Processor extends Thread {
	Spider sp;

	public Processor(Spider spi) {
		sp = spi;
	}

	public void run() {
		URL curr;
		ParserGetter kit = new ParserGetter();
		HTMLEditorKit.Parser parser = kit.getParser();
		HTMLEditorKit.ParserCallback callback = new LinkGetter(sp);
		while (true) {
			curr = sp.getURL();
			if (curr != null) {
				try {
					InputStream in;
					in = new BufferedInputStream(curr.openStream());
					InputStreamReader r = new InputStreamReader(in);
					parser.parse(r, callback, true);
				} catch (IOException e) {
					continue;
				} catch (Exception e) {
					System.out.println(curr);
					continue;
				}
			}
		}
	}
}